package com.cloudm.technician.ui.base

import android.annotation.SuppressLint
import android.app.Dialog
import android.os.Bundle
import android.support.design.widget.BottomSheetDialog
import android.view.LayoutInflater
import android.view.View
import com.cloudm.technician.R
import com.cloudm.technician.ui.widget.OnceClickListener
import kotlinx.android.synthetic.main.dialog_bottom_pic.view.*

/**
 * 作者: wesley
 * 时间: 2017/12/24
 * 描述: 和照片相关的从底部弹出对话框
 */
class PicBottomDialogFragment : BaseBottomDialogFragment() {

    var listener: OnItemClickListener? = null

    companion object {
        fun newInstance() = PicBottomDialogFragment()
    }

    override fun handleBundle(bundle: Bundle) {

    }

    @SuppressLint("InflateParams") override fun createDialog(): Dialog {
        val view = LayoutInflater.from(mContext).inflate(R.layout.dialog_bottom_pic, null)
        view.tvTakePic.setOnClickListener(ItemOnceClickListener())
        view.tvTakeFromGalley.setOnClickListener(ItemOnceClickListener())
        view.tvCancel.setOnClickListener(ItemOnceClickListener())
        return BottomSheetDialog(mContext).apply {
            setContentView(view)
        }
    }

    override fun onDetach() {
        super.onDetach()
        listener = null
    }


    inner class ItemOnceClickListener : OnceClickListener() {
        override fun onOnceClick(view: View) {
            dismiss()
            when (view.id) {
                R.id.tvTakePic -> listener?.takePic()
                R.id.tvTakeFromGalley -> listener?.takeFromGalley()
            }
        }
    }


    interface OnItemClickListener {

        fun takePic()

        fun takeFromGalley()
    }
}